import request from '@/utils/request'
import type { 
  ApiResponse, 
  Comment, 
  CommentRequest 
} from '@/types'

// 评论相关API
export const commentApi = {
  // 发布评论
  createComment: (data: CommentRequest): Promise<ApiResponse<Comment>> => {
    return request.post('/comments', data)
  },

  // 获取评论详情
  getComment: (id: number): Promise<ApiResponse<Comment>> => {
    return request.get(`/comments/${id}`)
  },

  // 更新评论
  updateComment: (id: number, data: Partial<CommentRequest>): Promise<ApiResponse<Comment>> => {
    return request.put(`/comments/${id}`, data)
  },

  // 删除评论
  deleteComment: (id: number): Promise<ApiResponse<string>> => {
    return request.delete(`/comments/${id}`)
  },

  // 获取文章评论树
  getCommentTree: (postId: number): Promise<ApiResponse<Comment[]>> => {
    return request.get(`/comments/posts/${postId}/comments`)
  }
}